//
//  EmotionVIew.m
//  ChatTool
//
//  Created by zhuxuehang on 13-10-10.
//  Copyright (c) 2013年 zhuxuehang. All rights reserved.
//
#import "EmotionView.h"
#import "UIUtil.h"
#import "MicroDef.h"
#import "EmotionPageView.h"
#import "MJExtension.h"
#import "EMotionModel.h"
#import "CHEmotionHelper.h"


static EmotionView *shared;


@implementation EmotionView
@synthesize horizMenu = _horizMenu;
@synthesize emoScroll = _emoScroll;
@synthesize items = _items;
@synthesize pageCon = _pageCon;
@synthesize delegate = _delegate;

- (void)dealloc
{
   
}

+(EmotionView*)defaultEmoView
{
    @synchronized(self)
    {
        if(shared == nil)
        {
            shared = [[EmotionView alloc] init];
        }
    }
    return shared;
}

+(EmotionView*)defaultEmoViewWithDelegate:(id)sender
{
    @synchronized(self)
    {
        if(shared == nil)
        {
            shared = [[EmotionView alloc] init];
            shared.emoScroll.delegate = sender;
        }
    }
    return shared;
}
- (id)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = RGBCOLOR(237, 237, 237);
        self.frame = CGRectMake(0, HARDWARE_SCREEN_HEIGHT - 64, HARDWARE_SCREEN_WIDTH, 180);
        self.emoPageView = [EmotionPageView defaultEmoPageView];
        _horizMenu = [[EmotiontoolView alloc] init];
        
        
        [self setDesign:nil];
    }
    return self;
}

-(void)setDesign:(id)sender
{
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, 0.5f)];
    line.backgroundColor = RGBCOLOR(212, 212, 212);
    [self addSubview:line];

    self.emoPageView.backgroundColor = RGBCOLOR(237, 237, 237);
    [self addSubview:self.emoPageView];
    self.emoPageView.frame = CGRectMake(0, 0.5, HARDWARE_SCREEN_WIDTH, 140.0f);
   self.emoPageView.emotionArray = [CHEmotionHelper defaultEmotions];
    
    [_horizMenu setFrame:CGRectMake(0,140, HARDWARE_SCREEN_WIDTH, 40)];
    _horizMenu.backgroundColor = RGBCOLOR(237, 237, 237);
    _horizMenu.delegate = self;
    [self addSubview:self.horizMenu];
   
    
}

- (void)emotiontoolViewDidSend
{
    if ([self.delegate respondsToSelector:@selector(emotionViewDidSend)]) {
        [self.delegate emotionViewDidSend];
    }
}

- (void)emotiontoolViewDidSelectEmotionWithType:(NSString *)emotionType
{
    if ([emotionType isEqualToString:@"defaultEmotion"]) {
       self.emoPageView.emotionArray = [CHEmotionHelper defaultEmotions];
    } else if ([emotionType isEqualToString:@"rencentEmotion"]){
        self.emoPageView.emotionArray = [CHEmotionHelper recentEmotions];
    }
}

#pragma mark -
#pragma mark HorizMenu Delegate
-(void) horizMenu:(MKHorizMenu *)horizMenu itemSelectedAtIndex:(NSUInteger)index
{
//    if (index==0) {
//        //显示发送
//        [UIView beginAnimations:nil context:NULL];
//        [UIView setAnimationDuration:0.3];
//        [_sendBtn setFrame:CGRectMake(self.horizMenu.frame.size.width - 60,self.horizMenu.frame.origin.y+5, 50, 30)];
//        [UIView commitAnimations];
//    }else
//    {
//        [UIView beginAnimations:nil context:NULL];
//        [UIView setAnimationDuration:0.3];
//        [_sendBtn setFrame:CGRectMake(self.horizMenu.frame.size.width + 1 ,self.horizMenu.frame.origin.y+5, 50, 30)];
//        [UIView commitAnimations];
//    }
//    self.selectionItemLabel.text = [self.items objectAtIndex:index];
}



@end
